package com.atstudent.gmall.product.controller;

import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.common.result.ResultCodeEnum;
import com.atstudent.gmall.product.dto.SkuInfoDto;
import com.atstudent.gmall.product.entity.SkuInfo;
import com.atstudent.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sku属性
 * @Author 薛有朋
 * @CreatDate 2024/11/25 21:03
 **/
@RestController
@RequestMapping(value = "/admin/product")
public class SkuInfoController {

    @Autowired
    private SkuInfoService skuInfoService;

    /**
     * 获取sku分页列表
     * @Author 薛有朋
     * @Date 2024/11/25 21:04
     **/
    @GetMapping(value = "/list/{page}/{limit}")
    public Result<Page> findByPage(@PathVariable(value = "page") Integer pageNum ,@PathVariable(value = "limit") Integer pageSize){
        Page page = skuInfoService.findByPage(pageNum , pageSize);
        return Result.ok(page);
    }

    /**
     * 添加sku
     * @Author 薛有朋
     * @Date 2024/11/26 20:47
     **/
    @PostMapping(value = "/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfoDto skuInfoDto){
        skuInfoService.saveSkuInfo(skuInfoDto);
        return Result.ok();
    }

    /**
     * 上架sku
     * @Author 薛有朋
     * @Date 2024/11/26 22:02
     **/
    @GetMapping(value = "/onSale/{skuId}")
    public Result onSale(@PathVariable(value = "skuId") Long skuId) {
        skuInfoService.onSale(skuId) ;
        return Result.ok() ;
    }

    /**
     * 下架sku
     * @Author 薛有朋
     * @Date 2024/11/26 22:02
     **/
    @GetMapping(value = "/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable(value = "skuId") Long skuId) {
        skuInfoService.cancelSale(skuId) ;
        return Result.ok() ;
    }

}
